#define _CRT_SECURE_NO_WARNINGS 1
#include"stack.h"
void init_stack(ST* s1)
{
	assert(s1);
	s1->stack = NULL;
	s1->top = 0;
	s1->capacity = 0;
}
void push_stack(ST* s1, STDateType x)
{
	assert(s1);
	if (s1->capacity == s1->top)
	{
		int newcapacity = s1->capacity == 0 ? 4 : s1->capacity * 2;
		s1->stack = (STDateType*)realloc(s1->stack,sizeof(STDateType) * newcapacity);
		if (s1->stack == NULL)
		{
			perror("push_stack");
		}
		s1->capacity = newcapacity;
	}
	s1->stack[s1->top] = x;
	s1->top++;
}
bool empty_stack(ST* s1)
{
	assert(s1);
	return s1->top == 0;
}

void pop_stack(ST* s1)
{
	assert(s1);
	assert(s1->top>0);
	s1->top--;
}
STDateType sttop(ST* s1)
{
	assert(s1);
	assert(s1->top > 0);
	return s1->stack[s1->top-1];
}
int size_stack(ST* s1)
{
	assert(s1);
	return s1->top;
}
void destroy_stack(ST* s1)
{
	assert(s1);
	free(s1->stack);
	s1->stack = NULL;
	s1->capacity = 0;
	s1->top = 0;
}